﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Threading;

using Gift.DAL;
using Gift.Model;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;
using Gift.Utile;

namespace WebApp.admin.goods
{
    public partial class category : BaseAdmin
    {
      
        tbCategoryBrand oCategoryBrand = new tbCategoryBrand();
     
        tbCategory oCategory = new tbCategory();


        // Methods
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string pathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
            try
            {
    
                if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
                {
                    this.oCategory = BaseFactory.theCategory.GetModel(base.Request.QueryString["id"]);
                }
                this.oCategory.categoryName = this.txtCategoryName.Value;
                this.oCategory.sortOrder = Convert.ToInt32(this.txtSortOrder.Value);
                this.oCategory.keywords = this.txtKeywords.Value;
                this.oCategory.description = this.txtaDescription.Value;
                this.oCategory.isShow = MathLibrary.ConvertNumToBool(base.Request.Form["isShow"]);
                string str2 = base.Request.Form["brand"];
                ArrayList list = new ArrayList();
                if (str2 != null)
                {
                    list = ArrayList.Adapter(str2.Split(new char[] { ',' }));
                }
                StringBuilder sbParentIds = new StringBuilder();
                if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
                {

                    tbCategory tempCategory = BaseFactory.theCategory.GetModel(base.Request.QueryString["id"]);
                    if (tempCategory != null && tempCategory.parentId.ToString() != "00000000-0000-0000-0000-000000000000")

                        sbParentIds.Append(tempCategory.parentId.ToString());
                    tempCategory = BaseFactory.theCategory.GetModel(tempCategory.parentId.ToString());

                    if (tempCategory != null && tempCategory.parentId.ToString() != "00000000-0000-0000-0000-000000000000")
                    {
                        sbParentIds.Append(",");
                        sbParentIds.Append(tempCategory.parentId.ToString());
                        tempCategory = BaseFactory.theCategory.GetModel(tempCategory.parentId.ToString());
                        if (tempCategory != null && tempCategory.parentId.ToString() != "00000000-0000-0000-0000-000000000000")
                        {
                            sbParentIds.Append(",");
                            sbParentIds.Append(tempCategory.parentId.ToString());
                            tempCategory = BaseFactory.theCategory.GetModel(tempCategory.parentId.ToString());
                            if (tempCategory != null && tempCategory.parentId.ToString() != "00000000-0000-0000-0000-000000000000")
                            {
                                sbParentIds.Append(",");
                                sbParentIds.Append(tempCategory.parentId.ToString());
                            }
                        }
                    }

                    this.oCategory.parentIdStr = sbParentIds.ToString();
                    if (BaseFactory.theCategory.Update(this.oCategory))
                    {
                       
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");window.location.href='categoryList.aspx?pid=" + this.oCategory.parentId + "';</script>");
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                    }
                }
                else if ((base.Request.QueryString["ot"] == "ad") && (base.Request.QueryString["pid"] != null))
                {
                    this.oCategory.id =  Guid.NewGuid();
                    this.oCategory.parentId = Guid.Parse(base.Request.QueryString["pid"]);
                    tbCategory tmpCategory = BaseFactory.theCategory.GetModel(base.Request.QueryString["pid"]);
                    if (tmpCategory != null)
                    {
                        this.oCategory.parentIdStr = tmpCategory.parentIdStr == null ? base.Request.QueryString["pid"] : tmpCategory.parentIdStr + "," + base.Request.QueryString["pid"];
                    }
                    else
                    {
                        this.oCategory.parentIdStr = "00000000-0000-0000-0000-000000000000";
                    }
                    this.oCategory.CompanyId = int.Parse(this.Administrator.CompanyId);
                    this.oCategory.categoryIdentity = BaseFactory.theCategory.Add(this.oCategory);
                
                    if (this.oCategory.categoryIdentity != 0)
                    {
                        foreach (string str3 in list)
                        {
                            this.oCategoryBrand.category = this.oCategory.categoryIdentity;
                            this.oCategoryBrand.brand = Convert.ToInt32(str3);
                            BaseFactory.theCategoryBrand.Add(this.oCategoryBrand);
                        }
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\");window.location.href='categoryList.aspx?pid=" + this.oCategory.parentId + "';</script>");
                    }
                    else
                    {
                        base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                    }
                }
            }
            catch
            {
                if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                }
            }
        }

        protected StringBuilder CategoryAdBind()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if ((base.Request.QueryString["pid"] == null) || (base.Request.QueryString["ot"] == null))
                {
                    return builder;
                }
                if ((base.Request.QueryString["pid"] == "00000000-0000-0000-0000-000000000000") && (base.Request.QueryString["ot"] == "ed"))
                {
                    DataTable categoryAdByCategory = BaseFactory.theCategoryAd.GetCategoryAdByCategory(base.Request.QueryString["id"]);
                    builder.AppendLine("<tr><td colspan=\"4\">分类广告</td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片左侧广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 186px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelSlidesLeft.jpg" : categoryAdByCategory.Rows[0]["slidesLeft"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：186*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesLeftAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesLeftUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 405px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelSlides1.jpg" : categoryAdByCategory.Rows[0]["slidesOne"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：810*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesOneAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesOneUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 405px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelSlides2.jpg" : categoryAdByCategory.Rows[0]["slidesTwo"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：810*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesTwoAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesTwoUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory1.jpg" : categoryAdByCategory.Rows[0]["categoryOne"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryOneAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryOneUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory2.jpg" : categoryAdByCategory.Rows[0]["categoryTwo"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryTwoAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryTwoUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告三：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory3.jpg" : categoryAdByCategory.Rows[0]["categoryThree"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryThreeAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryThreeUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告四：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory4.jpg" : categoryAdByCategory.Rows[0]["categoryFour"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryFourAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryFourUrl"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">中间广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelMiddle.jpg" : categoryAdByCategory.Rows[0]["middle"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：1000*310 分辨率：72像素 格式：jpg,bmp,gif,png<br >提示：高度可自定</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["middleAlt"].ToString()) + "\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["middleUrl"].ToString()) + "\" /></td></tr>");
                    return builder;
                }
                if ((base.Request.QueryString["pid"] == "00000000-0000-0000-0000-000000000000") && (base.Request.QueryString["ot"] == "ad"))
                {
                    builder.AppendLine("<tr><td colspan=\"4\">分类广告</td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片左侧广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelSlidesLeft.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：210*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"/cn/category_ad/ChannelSlides1.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：790*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"/cn/category_ad/ChannelSlides2.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：790*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory1.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory2.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告三：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory3.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告四：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory4.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                    builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">中间广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"/cn/category_ad/ChannelMiddle.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：1000*310 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                    builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                }
            }
            catch
            {
            }
            return builder;
        }

        private void CategoryBind()
        {
            try
            {
                DataTable categoryById = BaseFactory.theCategory.GetCategoryById(base.Request.QueryString["id"]);
                if (categoryById.Rows.Count > 0)
                {
                    if (categoryById.Rows[0]["parentId"].ToString() != "00000000-0000-0000-0000-000000000000")
                    {
                        DataTable table2 = BaseFactory.theCategory.GetCategoryById(categoryById.Rows[0]["parentId"].ToString());
                        if (table2.Rows.Count > 0)
                        {
                            this.lblParentCategory.InnerText = table2.Rows[0]["categoryName"].ToString();
                        }
                    }
                    else
                    {
                        this.lblParentCategory.InnerText = "顶级分类";
                    }
                    this.txtCategoryName.Value = categoryById.Rows[0]["categoryName"].ToString();
                    this.txtSortOrder.Value = categoryById.Rows[0]["sortOrder"].ToString();
                    if (Convert.ToInt32(categoryById.Rows[0]["isShow"]) == 1)
                    {
                        this.rdIsShow1.Checked = true;
                    }
                    else
                    {
                        this.rdIsShow0.Checked = true;
                    }
                    this.txtKeywords.Value = categoryById.Rows[0]["keywords"].ToString();
                    this.txtaDescription.Value = categoryById.Rows[0]["description"].ToString();
                }
            }
            catch
            {
            }
        }

        public StringBuilder GetBcakLocation()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if (base.Request.QueryString["id"] != null)
                {
                    DataTable categoryById = BaseFactory.theCategory.GetCategoryById(base.Request.QueryString["id"]);
                    if (categoryById.Rows.Count > 0)
                    {
                        builder.Append("openNewTab('分类列表','/admin/goods/categoryList.aspx?pid=" + categoryById.Rows[0]["parentId"].ToString() + "');");
                    }
                    return builder;
                }
                if (base.Request.QueryString["pid"] != null)
                {
                    builder.Append("openNewTab('分类列表','/admin/goods/categoryList.aspx?pid=" + base.Request.QueryString["pid"] + "');");
                }
            }
            catch
            {
            }
            return builder;
        }

        public StringBuilder GetBrand()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if (base.Request.QueryString["pid"] == null)
                {
                    return builder;
                }
                DataTable brandByCompanyAndParentId = BaseFactory.theBrand.GetBrandByCompanyAndParentId(base.Administrator.CompanyId, base.Request.QueryString["pid"]);
                DataTable categoryBrandByCategory = new DataTable();
                if (base.Request.QueryString["id"] != null)
                {
                    categoryBrandByCategory = BaseFactory.theCategoryBrand.GetCategoryBrandByCategory(Convert.ToInt32(BaseFactory.theCategory.GetCategoryById(base.Request.QueryString["id"]).Rows[0]["categoryIdentity"]));
                }
                if (brandByCompanyAndParentId.Rows.Count <= 0)
                {
                    return builder;
                }
                foreach (DataRow row in brandByCompanyAndParentId.Rows)
                {
                    bool flag = false;
                    if (categoryBrandByCategory.Rows.Count > 0)
                    {
                        foreach (DataRow row2 in categoryBrandByCategory.Rows)
                        {
                            if (Convert.ToInt32(row2["brand"]) == Convert.ToInt32(row["id"]))
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        builder.AppendLine("<input id=\"cb" + row["id"].ToString() + "\" name=\"brand\" value=\"" + row["id"].ToString() + "\" type=\"checkbox\" checked=\"checked\" />" + row["brandName"].ToString() + "");
                    }
                    else
                    {
                        builder.AppendLine("<input id=\"cb" + row["id"].ToString() + "\" name=\"brand\" value=\"" + row["id"].ToString() + "\" type=\"checkbox\" />" + row["brandName"].ToString() + "");
                    }
                }
            }
            catch
            {
            }
            return builder;
        }

        public StringBuilder GetTitle()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["id"] != null))
                {
                    base.ValidateLoginRule(Gift.Model.ENUM.ERule.GoodsCategoryEdit);
                    builder.Append("编辑分类");
                    return builder;
                }
                if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["pid"] != null))
                {
                    base.ValidateLoginRule(Gift.Model.ENUM.ERule.GoodsCategoryAdd);
                    builder.Append("添加分类");
                }
            }
            catch
            {
            }
            return builder;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
            //{
            //    base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
            //}
            if (!base.IsPostBack)
            {
                if (base.Request.QueryString["ot"] == "ed")
                {
                    base.ValidateLoginRule(Gift.Model.ENUM.ERule.GoodsCategoryEdit);
                }
                else
                {
                    base.ValidateLoginRule(Gift.Model.ENUM.ERule.GoodsCategoryAdd);
                }
                if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["id"] != null))
                {
                    this.CategoryBind();
                }
                else if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["pid"] != null))
                {
                    if (base.Request.QueryString["pid"] == "00000000-0000-0000-0000-000000000000")
                    {
                        this.lblParentCategory.InnerText = "顶级分类";
                    }
                    else
                    {
                        DataTable categoryById = BaseFactory.theCategory.GetCategoryById(base.Request.QueryString["pid"]);
                        if (categoryById.Rows.Count > 0)
                        {
                            this.lblParentCategory.InnerText = categoryById.Rows[0]["categoryName"].ToString();
                        }
                    }
                    this.rdIsShow1.Checked = true;
                }
            }
        }

    }
}